#include <linux/fs.h>
#include <linux/module.h>
#include <linux/uaccess.h>

#define FILE_NAME "/tmp/testfile"
#define BUFFER_SIZE 128

static struct file *file_ptr = NULL;
// static char *read_buffer = NULL;
// static char *write_buffer = "Hello from kernel module!\n";

static int __init
fileop_init (void)
{
  // >>> 实现文件访问操作。
  file_ptr = filp_open(FILE_NAME, O_RDWR|O_CREAT, 0644);

  if (IS_ERR(file_ptr) || file_ptr == NULL)
  {
    printk(KERN_ALERT "Failed to open file\n");
  }
  else
  {
    printk(KERN_INFO "File operation successful\n");
  }
  return 0;
}

static void __exit
fileop_exit (void)
{
  if (file_ptr)
    {
      filp_close (file_ptr, NULL);
      printk (KERN_INFO "File closed\n");
    }
}

module_init (fileop_init);
module_exit (fileop_exit);

MODULE_LICENSE ("GPL");
MODULE_AUTHOR ("Your Name");
MODULE_DESCRIPTION ("Simple File Operation Module");
